import axios from 'axios';import router from '..';const {defaults,interceptors}=axios;
defaults.baseURL=process.env.NODE_ENV==='production'?'//127.0.0.1:8080':'//127.0.0.1:8080'
defaults.timeout=10000;defaults.withCredentials = true
defaults.headers['X-Requested-With'] = 'XMLHttpRequest'
defaults.headers['t'] = localStorage.getItem('token') || ''
defaults.headers['s'] = localStorage.getItem('secret') || ''
defaults.headers.post['Content-Type'] = 'application/json'
defaults.headers.put['Content-Type'] = 'application/json'
interceptors.response.use(res=>{
  if (res.status!==200){console.log(res.status+"->"+res.statusText)}
  return res.data
}, ({response})=> {
  if (response?.status === 307) {
    router.push({ path: '/login' })
  }
  return response&&Promise.reject(response.status+" -> "+response.data);
});

export default axios